package.cpath = package.cpath .. ';C:/Users/win/AppData/Roaming/JetBrains/IdeaIC2020.3/plugins/intellij-emmylua/classes/debugger/emmy/windows/x86/?.dll'
local dbg = require('emmy_core')
dbg.tcpConnect('localhost', 9966)

package.path = package.path .. ";C:/Users/win/Documents/_lua/util/?.lua"

local Pq = require("Pq")


function Test1()
    local pq = Pq.new(function(a, b)
        return a < b
    end)
    assert(0 == pq:GetCount())
    assert("" == tostring(pq))
    assert(nil == pq:Peek())


    pq:Push(8)
    assert(1 == pq:GetCount())
    assert("8" == tostring(pq))
    assert(8 == pq:Peek())

    pq:Push(5)
    assert(2 == pq:GetCount())
    assert("5,8" == tostring(pq))
    assert(5 == pq:Peek())

    pq:Push(4)
    assert(3 == pq:GetCount())
    assert("4,5,8" == tostring(pq))
    assert(4 == pq:Peek())

    pq:Push(3)
    assert(4 == pq:GetCount())
    assert("3,4,5,8" == tostring(pq))
    assert(3 == pq:Peek())

    pq:Push(9)
    assert(5 == pq:GetCount())
    assert("3,4,5,8,9" == tostring(pq))
    assert(3 == pq:Peek())

    pq:Push(7)
    assert(6 == pq:GetCount())
    assert("3,4,5,7,8,9" == tostring(pq))
    assert(3 == pq:Peek())

    assert(3 == pq:Pop())
    assert(5 == pq:GetCount())
    assert("4,5,7,8,9" == tostring(pq))
    assert(4 == pq:Peek())

    pq:Clear()
    assert(0 == pq:GetCount())
    assert("" == tostring(pq))
    assert(nil == pq:Peek())

    pq:Push(8)
    pq:Push(5)
    pq:Push(4)
    pq:Push(3)
    for v in pq:GetIterator() do
        print("v:", v)
    end

    pq:Clear(Pq.ClearTypeEnum.FillNil)
    assert(0 == pq:GetCount())
    assert("" == tostring(pq))
    assert(nil == pq:Peek())

    pq:Push(8)
    pq:Push(5)
    pq:Push(4)
    pq:Push(3)
    pq:Clear(Pq.ClearTypeEnum.Keep)
    assert(0 == pq:GetCount())
    assert("" == tostring(pq))
    assert(nil == pq:Peek())
end
Test1()